<script setup lang="ts">
import { computed, ref } from 'vue'
import chart from '@/components/common/chart.vue'

interface chartData {
  name: string[];
  series: number[]
}

const props = defineProps<{
  data: chartData[],
  height?: string,
  width?: string,
  color?: string[]
}>()

const width = props.width || '100%';
const height = props.height || '100%';
const color = props.color || ['rgba(63, 177, 227, 1)', 'rgba(107, 230, 193, 1)']

const options = computed(() => {
  let opt = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      left: '5%',
      top: '5%',
      right: '5%',
      bottom: '5%',
      containLabel: true
    },
    xAxis: {
      type: 'log',
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      data: props.data?.name,
      axisTick: {
        show:false
      }
    },
    series: [
      {
        name: '2011',
        type: 'bar',
        itemStyle: {
          borderRadius:[0, 3, 3, 0]
        },
        label: {
          show: false,
          position: 'right',
        },
        barWidth: 10,
        data: props.data?.series
      },
    ],
    color,
  }
  return opt;
})

</script>

<template>
  <div :style="{ width: `${width}`, height: `${height}` }" class="chart-box">
    <chart class="chart" :options="options" />
  </div>
</template>

<style scoped lang="stylus">
.chart-box {
  .chart {
    width: 100%;
    height: 100%;
  }
}
</style>